/*
 *  AudioPlayerTester.cpp
 *  SoundController0002
 *
 *  Created by jiro on 10/07/09.
 *  Copyright 2010 jiro music. All rights reserved.
 *
 */

#include "AudioPlayerTester.h"
#include "../AudioRecorder.h"
#include "../AudioPlayer.h"
#include "../Constants.h"
#include "CustomAssert.h"

namespace sc
{
	void AudioPlayerTester::TestAll()
	{
		Test_Play_000();
	}

	void AudioPlayerTester::Test_Play_000()
	{		
		const SoundElement32* element = SoundElementFactory32::Create(
			0.25, & LineFactory::Create( Line::Type_Straight, 0,    1,	0.25, 1 ),
			0.50, & LineFactory::Create( Line::Type_Straight, 0.25, 1,	0.50, 1 ),
			0.75, & LineFactory::Create( Line::Type_Straight, 0.50, 1,	0.75, 1 ),
			2.0,  & LineFactory::Create( Line::Type_Straight, 0.75, 1,	1.0,  1 ),
			WaveTableFactory::Create( WaveTable::Type_Sine, 440.0 ) );
		const SoundElement32* element2 = SoundElementFactory32::Create(
			0.25, & LineFactory::Create( Line::Type_Straight, 0,    1,	0.25, 1 ),
			0.50, & LineFactory::Create( Line::Type_Straight, 0.25, 1,	0.50, 1 ),
			0.75, & LineFactory::Create( Line::Type_Straight, 0.50, 1,	0.75, 1 ),
			2.0,  & LineFactory::Create( Line::Type_Straight, 0.75, 1,	1.0,  1 ),
			WaveTableFactory::Create( WaveTable::Type_Sine, 441.0 ) );
		const SoundElement32* element3 = SoundElementFactory32::Create(
			0.25, & LineFactory::Create( Line::Type_Straight, 0,    1,	0.25, 1 ),
			0.50, & LineFactory::Create( Line::Type_Straight, 0.25, 1,	0.50, 1 ),
			0.75, & LineFactory::Create( Line::Type_Straight, 0.50, 1,	0.75, 1 ),
			2.0,  & LineFactory::Create( Line::Type_Straight, 0.75, 1,	1.0,  1 ),
			WaveTableFactory::Create( WaveTable::Type_Sine, 435.0 ) );

		vector< AudioData32 > audioData0;
		vector< AudioData32 > audioData1;

		AudioRecorder32 recorder( 2, 1 );
		recorder.Record( 0, 0, 0, element );
		recorder.Record( 1, 0, 0, element2 );
		recorder.Record( 0, 0, 0, element3 );

		recorder.Record( 1, 0, 0, element );
		recorder.Record( 0, 0, 0, element2 );
		recorder.Record( 1, 0, 0, element3 );
		
		recorder.GetAudioData( 0, audioData0 );
		recorder.GetAudioData( 1, audioData1 );

		vector< vector< AudioData32 >* > audioDataByChannel;
		audioDataByChannel.push_back( & audioData0 );
		audioDataByChannel.push_back( & audioData1 );

		AudioPlayer player;
		player.LoadAudioData( audioDataByChannel );
		player.Play( 0 );
		while ( player.IsPlaying() )
		{
			usleep( 1000 );
		}
		player.Stop();
	}
}
